home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * © Copyright 1982-1994, Rob Glanville
- *
- * by Rob Glanville
- *
- * 4 Apr 94
- *
- * robix.c - Debugger for PCI testing
- *
- */
-
- #pragma segment robix
-
- #include <stdio.h>
-
- #define UInt8 unsigned char /* Used for casting */
- #define UInt16 unsigned short /* Used for casting */
- #define UInt32 unsigned long /* Used for casting */
- #define PInt8 *(UInt8 *) /* Used for physical address casting */
- #define PInt16 *(UInt16 *) /* Used for physical address casting */
- #define PInt32 *(UInt32 *) /* Used for physical address casting */
- #define VInt8 *(volatile UInt8 *) /* Used for physical address casting to memory */
- #define VInt16 *(volatile UInt16 *)/* Used for physical address casting to memory */
- #define VInt32 *(volatile UInt32 *)/* Used for physical address casting to memory */
- #define True 0xffffffff
- #define False 0x00000000
- #define CR 0x0d
- #define LF 0x0a
- #define Rubout 0x08
- #define Tab 0x09
- #define NOP 0x00
- #define Null 0x00
- #define Blank 0x20
-
-
- /************************************* ROBIX Constants *********************************************/
-
- static const UInt8 Digits[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- static const UInt8 Delimiters[] = {0x09,0x0a,0x1b,0x20,0x21,0x22,0x23,0x24,0x25,0x26,
- 0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x3a,
- 0x3b,0x3c,0x3d,0x3e,0x40,0x5b,0x5c,0x5d,0x5e,0x5f,
- 0x00,0x60,0x7b,0x7c,0x7d,0x7e,0x7f,0x3f,0x0d};
-
- /************************************* ROBIX Variables *********************************************/
-
- UInt8 CommandLine[256]; /* Input buffer */
- UInt8 delimiter; /* Delimiter between arguments */
- UInt8 AsciiBuf[19]; /* A buffer for output */
- UInt8 Argument[0x80]; /* The arguments go here one by one */
- UInt8 TabSize; /* Size of tab stops */
- UInt8 KeyboardFrom; /* Where is the keyboard input coming from? */
-
- UInt16 ArgSize; /* Argument size */
- UInt16 CPointer; /* Command pointer */
-
- UInt32 CommandIndex; /* The index into command buffer */
- UInt32 number; /* A place for all numbers input */
- UInt32 BufPtr; /* Alias buffer pointer for unions */
- UInt32 Base; /* Base address for all accesses */
- UInt32 Offset; /* Offset address for some accesses */
- UInt32 accessMethod; /* Type of hardware access */
-
-
- /************************************* External Routines **********************************************/
- extern void PCIComplianceTest();
- extern void DisplayConfiguration();
-
- /* Access to PCI configuration space is hardware dependent */
- extern UInt8 Read8_Config (UInt32 RegisterOffset);
- extern void Write8_Config (UInt32 RegisterOffset,UInt8 Data);
- extern UInt16 Read16_Config (UInt32 RegisterOffset);
- extern void Write16_Config(UInt32 RegisterOffset,UInt16 Data);
- extern UInt32 Read32_Config (UInt32 RegisterOffset);
- extern void Write32_Config(UInt32 RegisterOffset,UInt32 Data);
-
-
- UInt8 Int8Read (address) UInt32 address; {
- return(VInt8 address);
- }
-
- UInt16 Int16Read (address) UInt32 address; {
- return(VInt16 address);
- }
-
- UInt32 Int32Read (address) UInt32 address; {
- return(VInt32 address);
- }
-
- void Int8Write (address,data) UInt32 address; UInt8 data; {
- VInt8 address = data;
- }
-
- void Int16Write(address,data) UInt32 address; UInt16 data; {
- VInt16 address = data;
- }
-
- void Int32Write(address,data) UInt32 address; UInt32 data; {
- VInt32 address = data;
- }
-
- UInt8 kbhit() {
- return(Null);
- }
-
- UInt8 inchar() {
- return(getchar());
- }
-
- void outchar(character) UInt8 character; {
- putchar(character);
- }
-
- void printstr(string) UInt8 *string; {
- while (*string != Null) {
- if (*string != '\r')
- outchar(*string++);
- else string++;
- }
- }
-
- void SyntaxError() {
- printstr("Syntax error\r\n");
- }
-
- /*
- LineIn get input from the user and places it in a command lime buffer
- for later parsing. This is nothing more than echo characters with rubouts
- and tabs.
- */
- void LineIn() {
- UInt8 character,exit;
- UInt16 index,TabSpace;
- if (delimiter == CR) {
- CommandIndex = Null;
- exit = False;
- CPointer = Null;
- do {
- character = inchar();
- if (character == Rubout) {
- if (CommandIndex > 0) {
- outchar(Rubout);
- outchar(Blank);
- outchar(Rubout);
- CommandIndex--;
- }
- }
- else if (character == CR) {
- CommandLine[CommandIndex++] = CR;
- exit = True;
- }
- else if (character == Tab) {
- TabSpace = TabSize - ((CommandIndex+1) % TabSize);
- for (index=0;index<TabSpace;index++) {
- outchar(Blank);
- CommandLine[CommandIndex++] = Blank;
- }
- }
- else {
- CommandLine[CommandIndex++] = character;
- }
- } while (!exit);
- }
- else delimiter = CR;
- }
-
- /*
- Takes a pointer to a character and changes lower case to upper case.
- */
- void Upper(character) UInt8 *character; {
- if ((*character >= 'a') && (*character <= 'z')) *character -= Blank;
- }
-
- /*
- ScanDelimiters simply sets the command line pointer to point to the
- first non delimiter so the user can type garbage and there won't be
- a syntax error.
- */
- void ScanDelimiters() {
- UInt16 index;
- UInt8 found;
- do {
- found = False;
- if ((CommandLine[CPointer] >= '1') & (CommandLine[CPointer] <= '9')) found = False;
- else if ((CommandLine[CPointer] >= 'a') & (CommandLine[CPointer] <= 'z')) found = False;
- else if ((CommandLine[CPointer] >= 'A') & (CommandLine[CPointer] <= 'Z')) found = False;
- else for (index=0;index<sizeof(Delimiters)-2;index++) {
- if (CommandLine[CPointer] == Delimiters[index]) found = True;
- }
- if (found) CPointer++;
- } while (found);
- }
-
- /*
- getarg simply parses the command line and places and arguments in
- a buffer called 'Argument'. Whatever delimiter is found is placed
- in 'delimiter' and the variable 'ArgSize' has the byte count of
- the argument. You make a call to getarg and check the size for non-zero
- to tell when one is found. Keep making calls until you get an argument
- or the delimiter is a cursor return which indicates the end of the
- command line. If you want a number, then use GetValue.
- */
- void getarg() {
- UInt16 index,ArgPtr;
- UInt8 found;
- ArgPtr = Null;
- do {
- found = False;
- for (index=0;index<sizeof(Delimiters);index++) {
- if (CommandLine[CPointer] == Delimiters[index]) {
- delimiter = Delimiters[index];
- if (delimiter != CR) CPointer++;
- found = True;
- break;
- }
- }
- if (!found) Argument[ArgPtr++] = CommandLine[CPointer++];
- } while (!found);
- Argument[ArgPtr] = Null;
- ArgSize = ArgPtr;
- }
-
- /*
- GetValue returns true if a hexadecimal number was found in the
- command line. Otherwise it returns false. If a nubmer is found,
- it is placed in the global variable called 'number'. Repeated
- calls to GetValue will get multiple parameters to use in a command.
- */
- UInt16 GetValue() {
- UInt8 found;
- UInt16 index,loop;
- if (delimiter == ',') return(False);
- found = False;
- number = Null;
- do {
- getarg(); /* Get one argument from the command line */
- if (ArgSize) {
- /* Check for all digits in the argument */
- for (index=0;index<ArgSize;) {
- Upper(&Argument[index]);
- found = False;
- for (loop=0;loop<0x10;loop++) {
- if (Argument[index] == Digits[loop]) {
- Argument[index] = loop;
- found = True;
- break;
- }
- }
- if (!found) break;
- else index++;
- }
- /* Convert ascii to hex */
- if (found) for (index=0;index<ArgSize;index++) {
- number = ((number * 0x10) + Argument[index]);
- }
- }
- } while ((!found) && (delimiter != CR) && (delimiter != ','));
- return(found);
- }
-
- void nibble(data) UInt8 data; {
- if (data > 9) outchar(data + '7');
- else outchar(data + '0');
- }
-
- void byteout(data) UInt8 data; {
- nibble((data / 0x10) & 0x0f);
- nibble(data & 0x0f);
- }
-
- void wordout(data) UInt16 data; {
- byteout((UInt8)(data / 0x100) & 0xff);
- byteout((UInt8)data & 0xff);
- }
-
- void longout(data) UInt32 data; {
- wordout((UInt16)(data / 0x10000) & 0xffff);
- wordout((UInt16)data & 0xffff);
- }
-
- void decout(data) UInt32 data; {
- UInt8 Decimal;
- Decimal = data / 1000000000;
- /* nibble(Decimal); */
- data = data % 1000000000;
- Decimal = data / 100000000;
- /* nibble(Decimal); */
- data = data % 100000000;
- Decimal = data / 10000000;
- /* nibble(Decimal); */
- data = data % 10000000;
- Decimal = data / 1000000;
- /* nibble(Decimal); */
- data = data % 1000000;
- Decimal = data / 100000;
- /* nibble(Decimal); */
- data = data % 100000;
- Decimal = data / 10000;
- /* nibble(Decimal); */
- data = data % 10000;
- Decimal = data / 1000;
- /* nibble(Decimal); */
- data = data % 1000;
- Decimal = data / 100;
- /* nibble(Decimal); */
- data = data % 100;
- Decimal = data / 10;
- nibble(Decimal);
- data = data % 10;
- nibble(data);
- }
-
- void crlf() {
- printstr("\n");
- }
-
- /************************************* Commands *********************************************/
-
- /* Fill in the help menu when you add a new command */
- void Help() {
- printstr("?) Print this menu\r\n");
- /* printstr("A) \r\n"); */
- printstr("B) Byte read or write to config space (offset,data)\r\n"); /**/
- /* printstr("C) \r\n"); */
- printstr("D) Display configuration space\r\n");
- /* printstr("E) \r\n"); */
- /* printstr("F) \r\n"); */
- /* printstr("G) \r\n"); */
- /* printstr("H) \r\n"); */
- /* printstr("I) \r\n"); */
- /* printstr("J) \r\n"); */
- /* printstr("K) \r\n"); */
- printstr("L) Long read or write to config space (offset,data)\r\n"); /**/
- /* printstr("M) \r\n"); */
- /* printstr("N) \r\n"); */
- /* printstr("O) \r\n"); */
- /* printstr("P) \r\n"); */
- /* printstr("Q) \r\n"); */
- /* printstr("R) \r\n"); */
- printstr("S) Short read or write to config space (offset,data)\r\n"); /**/
- /* printstr("T) \r\n"); */
- /* printstr("U) \r\n"); */
- /* printstr("V) \r\n"); */
- /* printstr("W) \r\n"); */
- /* printstr("X) \r\n"); */
- /* printstr("Y) \r\n"); */
- /* printstr("Z) \r\n"); */
- }
-
- /************************************* Main Loop ********************************************/
-
-
- void main() {
- UInt32 Address;
- UInt8 Exit;
- delimiter = CR;
- TabSize = 8;
- Exit = False;
- printf("PCI Compliance test, Configuration Space\n\nBy Rob Glanville\n\n");
- PCIComplianceTest(); /* Call the test sequencer and run some tests */
- while (!Exit) {
- if (delimiter == CR) printstr(">");
- LineIn();
- ScanDelimiters(); /* Point to first non Blank */
- Upper(&CommandLine[CPointer]);
- switch(CommandLine[CPointer++]) {
- case '?' :
- Help();
- break;
- case CR :
- break;
- case 'A' :
- break;
- case 'B' :
- if (GetValue()) Address = number;
- else Address = 0;
- if (GetValue()) {
- Write8_Config(Address,number);
- }
- else {byteout(Read8_Config(Address));crlf();}
- break;
- case 'C' :
- break;
- case 'D' :
- DisplayConfiguration();
- break;
- case 'E' :
- break;
- case 'F' :
- break;
- case 'G' :
- break;
- case 'H' :
- break;
- case 'I' :
- break;
- case 'J' :
- break;
- case 'K' :
- break;
- case 'L' :
- if (GetValue()) Address = number;
- else Address = 0;
- if (GetValue()) {
- Write32_Config(Address,number);
- }
- else {longout(Read32_Config(Address));crlf();}
- break;
- case 'M' :
- break;
- case 'N' :
- break;
- case 'O' :
- break;
- case 'P' :
- break;
- case 'Q' :
- break;
- case 'R' :
- break;
- case 'S' :
- if (GetValue()) Address = number;
- else Address = 0;
- if (GetValue()) {
- Write16_Config(Address,number);
- }
- else {wordout(Read16_Config(Address));crlf();}
- break;
- case 'T' :
- break;
- case 'U' :
- break;
- case 'V' :
- break;
- case 'W' :
- break;
- case 'X' :
- break;
- case 'Y' :
- break;
- case 'Z' :
- break;
- default :
- printstr("Unknown command\r\n");
- delimiter = CR;
- break;
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-